package lovo01.lesson05;

import javax.swing.*;

public class Transition {
    public static void main(String[] args) {
        String sun = "[A-Z]{1}[a-z]{1,}[A-Z]{1}[a-z]{1,}";
        while (true) {
            String name = JOptionPane.showInputDialog("请输入驼峰命名法的单词：");
            if (name.matches(sun)) {
                for (int i = 0;i < name.length();i++){
                    char[] charAry = name.toCharArray();
                    if (charAry[i] >= 65 && charAry[i] <= 90){
                        charAry[i] += 32;
                        if (i > 0){
                            System.out.print("_");
                        }
                        System.out.print(charAry[i]);
                        continue;
                    }
                    System.out.print(charAry[i]);
                }
                break;
            } else {
                JOptionPane.showMessageDialog(null, "输入错误，请重新输入");
            }
        }
    }
}
